import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/common/xindong_button.dart';

// 编辑文本框
class XinDongInputTextMultiLineYeMian extends StatelessWidget {
  final String title;
  final String placeholder;
  final String? value;
  final Function(String text) doneCallback;

  const XinDongInputTextMultiLineYeMian({
    Key? key,
    required this.title,
    required this.placeholder,
    required this.value,
    required this.doneCallback,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final TextEditingController editController = TextEditingController(text: value);
    return Scaffold(
      appBar: XinDongAppBar(title),
      body: GestureDetector(
        onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
        child: ListView(
          children: [
            const SizedBox(height: 50),
            Container(
              color: DZColors.cellColor,
              height: 150,
              padding: const EdgeInsets.only(left: 16, right: 16),
              child: TextField(
                maxLines: null,
                textAlign: TextAlign.start,
                controller: editController,
                keyboardType: TextInputType.text,
                style: const TextStyle(
                    color: DZColors.contentColor, fontSize: 16.0, fontWeight: FontWeight.normal, height: 1.2),
                inputFormatters: [LengthLimitingTextInputFormatter(100)],
                decoration: InputDecoration(
                  // 设置这个之后，居中
                  contentPadding: const EdgeInsets.only(top: 16, bottom: 16),
                  // 占位符
                  hintText: placeholder,
                  // 占位符样式
                  hintStyle: const TextStyle(
                      color: DZColors.placeholderColor, fontSize: 16.0, fontWeight: FontWeight.normal, height: 1.2),
                  // 边框、圆角
                  border: const OutlineInputBorder(borderSide: BorderSide.none),
                ),
              ),
            ),
            const SizedBox(height: 50),
            Container(
              height: 52,
              padding: const EdgeInsets.only(left: 16, right: 16),
              child: XinDongCommonButton(
                "确定",
                onTap: () {
                  String text = editController.text.trim();
                  doneCallback(text);
                  Navigator.pop(context, text);
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}
